<template>
    <div style="display:flex;align-items: center;" @click="doClick" >
        <el-icon :size="size" class="cb3" >
            <CloseBold v-if="typeof(modelValue)=='boolean' && modelValue==false" color="red" />
            <Select v-else-if="modelValue == true" color="green" />
            <FullScreen v-else color="#dcdcdc" />
        </el-icon>
        <slot></slot>
    </div>
</template>

<script>

import {CloseBold, Select, FullScreen} from "@element-plus/icons-vue"

export default {
    name: "MyCheckBox3",
    inject: {
        CheckAll: { default: null },
    },
    emits: ["update:modelValue"],
    props: {
        modelValue: [String, Boolean],
        disabled: Boolean,
        size: {
            type: Number,
            default: 32
        },
    },
    mounted() {
        if (this.CheckAll) {
            this.CheckAll.addItem(this);
        }
    },
    unmounted() {
        if (this.CheckAll) {
            this.CheckAll.removeItem(this);
        }
    },
    methods: {
        doCheckAll(checked) {
            if (!this.disabled) {
                this.$emit('update:modelValue', checked);
            }
        },
        doClick() {
            if (this.disabled) return;
            if (this.modelValue == true) {
                this.$emit("update:modelValue", false)
            } else if (typeof(this.modelValue)=="boolean" && this.modelValue == false) {
                this.$emit("update:modelValue", null)
            } else {
                this.$emit("update:modelValue", true)
            }
        }
    },
}
</script>

<style scoped>
    .cb3{
        padding: 4px;
        border: 1px solid #ccc;
    }
</style>